import numpy as np
import time
import os
os.environ["OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS"] = "0"
import cv2
cap = cv2.VideoCapture(0,cv2.CAP_MSMF)#打开内置摄像机
cap.set(cv2.CAP_PROP_FRAME_HEIGHT,1080)
cap.set(cv2.CAP_PROP_FRAME_WIDTH,1920)
cap.set(cv2.CAP_PROP_FPS, 60)
flag = 1#播放视频
count = 0;#记录照相的次数
while cap.isOpened():#当摄像头打开时
    # ti=time.time()
    ret,frame=cap.read()#读取当前摄像头画面
    # print(time.time()-ti)
    # time.sleep(0.01)
    L=frame[:,0:1920]
    cv2.imshow('l',L)#显示当前摄像头画面q
    if cv2.waitKey(flag)==ord(' '):#按下空格键拍照
        c = str(count)#将countint转换成str型
        print(r'./img/'+c+'.jpg')
        cv2.imwrite(r'./img/'+c+'.jpg',L)#保存图片
        count=count+1#计数加一
    if cv2.waitKey(flag)==ord('q'):#退出循环
        break;
cv2.destroyAllWindows()#关闭所有窗口
cap.release()#释放摄像头